package com.neusoft.neuiotms.dcam.fixed.converter;

import java.text.DecimalFormat;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcam.fixed.dto.AssetLifeCycleDTO;
import com.neusoft.neuiotms.dcam.fixed.model.Asset;
import com.neusoft.neuiotms.dcam.fixed.model.AssetLifeCycle;

@Component
public class AssetLifeCycleConverter extends AbstractConverter<AssetLifeCycle, AssetLifeCycleDTO> {

    DecimalFormat numberFormat = new DecimalFormat("##,##0.00");

    @Override
    public AssetLifeCycle toModel(final AssetLifeCycleDTO dto) {
        return null;
    }

    public AssetLifeCycle toModel(final Asset a) {
        final AssetLifeCycle model = new AssetLifeCycle();
        model.setCode(a.getCode());
        model.setType(a.getType());
        model.setName(a.getName());
        model.setBooks(a.getBooks());
        model.setUsedate(a.getUsedate());
        model.setGetdate(a.getGetdate());
        model.setOwnvalue(a.getOwnvalue());
        model.setDepreciationstatus(a.getDepreciationstatus());
        model.setDepreciationmonth(a.getDepreciationmonth());
        model.setDepreciationtotal(a.getDepreciationtotal());
        model.setMonth(a.getMonth());
        model.setValuetype(a.getValuetype());
        model.setMoney(a.getMoney());
        model.setFundsfinancial(a.getFundsfinancial());
        model.setUnfundsfinancial(a.getUnfundsfinancial());
        model.setEquity(a.getEquity());
        model.setSource(a.getSource());
        model.setUsetype(a.getUsetype());
        model.setStatus(a.getStatus());
        model.setUseDept(a.getUseDept());
        model.setManageDept(a.getManageDept());
        model.setUserName(a.getUserName());
        model.setQuantity(a.getQuantity());
        model.setCreator(a.getCreator());
        model.setBelongTo(a.getBelongTo());
        model.setSubmmitTo(a.getSubmmitTo());
        model.setSpecification(a.getSpecification());
        model.setLocated(a.getLocated());
        model.setOriginCode(a.getOriginCode());
        model.setBrand(a.getBrand());
        model.setIdleValue(a.getIdleValue());
        model.setHandoverDate(a.getHandoverDate());
        model.setBackup(a.getBackup());
        model.setRemark(a.getRemark());
        model.setPurpose(a.getPurpose());
        model.setProduce(a.getProduce());
        model.setManufacturerEndDate(a.getManufacturerEndDate());
        model.setIsDocumentAll(a.getIsDocumentAll());
        model.setBusinessSystem(a.getBusinessSystem());
        model.setContractNameAndCode(a.getContractNameAndCode());
        model.setSequence(a.getSequence());
        model.setIsScrapped(a.getIsScrapped());
        model.setOfficeComputerRoomAddress(a.getOfficeComputerRoomAddress());
        model.setOfficeAddress(a.getOfficeAddress());

        return model;
    }

    @Override
    public AssetLifeCycleDTO toDTO(final AssetLifeCycle model, final boolean forListView) {
        final AssetLifeCycleDTO dto = new AssetLifeCycleDTO();
        dto.setId(model.getId());
        dto.setCreateTime(model.getCreateTime());
        dto.setCode(model.getCode());
        if (model.getType() != null) {
            dto.setAssetTypeId(model.getType().getId());
            dto.setAssetTypeCode(model.getType().getCode());
            dto.setAssetTypeName(model.getType().getName());
            if (model.getType().getParent() != null) {
                dto.setCategory(model.getType().getParent().getName());
            }
        }
        dto.setName(model.getName());
        dto.setBooks(model.getBooks());

        dto.setUserName(model.getUserName());
        dto.setUsedate(model.getUsedate());
        dto.setGetdate(model.getGetdate());
        dto.setOwnvalue(model.getOwnvalue());
        dto.setDepreciationstatus(model.getDepreciationstatus());
        dto.setDepreciationmonth(model.getDepreciationmonth());
        dto.setDepreciationtotal(model.getDepreciationtotal());
        dto.setMonth(model.getMonth());
        dto.setValuetype(model.getValuetype());
        dto.setMoney(model.getMoney());
        dto.setFundsfinancial(model.getFundsfinancial());
        dto.setUnfundsfinancial(model.getUnfundsfinancial());
        dto.setEquity(model.getEquity());
        dto.setUsetype(model.getUsetype());
        dto.setStatusDesc(model.getStatus());
        dto.setSourceDesc(model.getSource());
        dto.setUseDeptDesc(model.getUseDept());
        dto.setManageDeptDesc(model.getManageDept());
        dto.setUserName(model.getUserName());
        dto.setQuantity(model.getQuantity());
        dto.setCreator(model.getCreator());
        dto.setBelongTo(model.getBelongTo());
        dto.setSubmmitTo(model.getSubmmitTo());
        dto.setSpecification(model.getSpecification());
        dto.setLocated(model.getLocated());
        dto.setOriginCode(model.getOriginCode());
        dto.setBrand(model.getBrand());
        dto.setIdleValue(model.getIdleValue());
        dto.setHandoverDate(model.getHandoverDate());
        dto.setBackup(model.getBackup());
        dto.setRemark(model.getRemark());
        dto.setPurpose(model.getPurpose());
        dto.setProduce(model.getProduce());

        dto.setManufacturerEndDate(model.getManufacturerEndDate());
        if (model.getIsDocumentAll() != null) {
            dto.setIsDocumentAll(model.getIsDocumentAll().booleanValue() == true ? "是" : "否");
        } else {
            dto.setIsDocumentAll(StringUtils.EMPTY);
        }
        dto.setBusinessSystem(model.getBusinessSystem());
        if (model.getIsScrapped() != null) {
            dto.setIsScrapped(model.getIsScrapped().booleanValue() == true ? "是" : "否");
        } else {
            dto.setIsScrapped(StringUtils.EMPTY);
        }

        dto.setContractNameAndCode(model.getContractNameAndCode());
        dto.setOfficeAddress(model.getOfficeAddress());
        dto.setOfficeComputerRoomAddress(model.getOfficeComputerRoomAddress());
        dto.setSequence(model.getSequence());

        //        dto.setStatusDesc(model.getStatus() == null ? null : model.getStatus().getDesc());

        dto.setUpdateTime(model.getUpdateTime());

        return dto;
    }

}
